﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace testStdfFileWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        private void FileOpen_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //dlg.FileName = "Document";
            dlg.DefaultExt = ".std_1";
            dlg.Filter = "STDF Files (*.stdf;*.std_1)|*.stdf;*.std_1|All files (*.*)|*.*";

            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                string fileName = dlg.FileName;

                string fileExt = System.IO.Path.GetExtension(fileName);

                //int initialDataTableCount = MainApp.Current.project.dataSet.Tables.Count;
                //int initialDataTableCount = (Application.Current as App).project.dataSet.Tables.Count;

                STDFOpenDialog openDlg = new STDFOpenDialog();
                openDlg.fileTextBox.Text = fileName;
                openDlg.infoTextBox.Text = fileName;
                openDlg.ShowDialog();

                DataTable newTable = new DataTable(fileName);
                DataTable newHeaderTable = new DataTable("Properties_" + fileName);

                //test.DataFileReader.loadSTDF(fileName, ref newTable, ref newHeaderTable);
                bool success = false;
                stdf.StdfFile stdfFile = new stdf.StdfFile();

                stdfFile.loadMIR = (bool) openDlg.cbMIR.IsChecked;
                stdfFile.loadSDR = (bool)openDlg.cbSDR.IsChecked;
                stdfFile.loadWIR = (bool)openDlg.cbWIR.IsChecked;
                stdfFile.loadPRR = (bool)openDlg.cbPRR.IsChecked;
                //stdfFile.loadPRR = true;
                stdfFile.loadPTR = (bool)openDlg.cbPTR.IsChecked;
                stdfFile.loadFTR = (bool)openDlg.cbFTR.IsChecked;
                stdfFile.ignoreAlarm = (bool)openDlg.cbIgnoreAlarms.IsChecked;
            }


        }

        private void FileExit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}
